package com.cloud.code.leetcode;

/**
 * 75. 颜色分类
 */
public class Demo8 {

    public static void main(String[] args) {
        sortColors(new int[]{1,2,0});
    }

    public static void sortColors(int[] nums) {
        int left = 0;
        int right = nums.length - 1;
        int cur = 0;

        while (cur <= right) {
            int temp = nums[cur];
            if (temp > 1) {
                swap(nums, cur, right);
                right--;
            } else if (temp < 1) {
                swap(nums, cur, left);
                cur++;
                left++;
            } else {
                cur++;
            }
        }

    }


    public static void swap(int[] nums, int a, int b) {
        int tem = nums[a];
        nums[a] = nums[b];
        nums[b] = tem;
    }
}
